/********************************************
Name : TestNewCaseWebFormController
Created By : dthekumparampil
Created Date : Feb 3, 2013
Description : Test Coverage for NewCaseWebFormController
********************************************/
/********************************************
Name : TestNewCaseWebFormController
Done By : Allam Venakata Suneetha
Created Date : Feb 26, 2013
Description : Test Coverage for NewCaseWebFormController
********************************************/
@isTest
private class TestNewCaseWebFormController {
    
    
    
   
  //added  by suneetha
      public static list<West_Case_Names__c> createWestCaseNames_webform (){
        
        /*Creating West_Case_Names__c values*/
        
        list<West_Case_Names__c> testCasenameslist= new  list<West_Case_Names__c> ();
        
        West_Case_Names__c newRecord1 = new West_Case_Names__c(name='Call Applicant', West_Case_Name_Category__c='Academic', West_Case_Name_Activity__c='Program', 
        West_Case_Group__c='Administration',  West_Queue_Name__c='CM - Queue 19' ,West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
        
        testCasenameslist.add(newRecord1);
        
        West_Case_Names__c newRecord2 = new West_Case_Names__c(name='Email Applicant', West_Case_Name_Category__c='Academic', West_Case_Name_Activity__c='Program', 
        West_Case_Group__c='Administration', West_Queue_Name__c='CM - Queue 19', West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
            
            testCasenameslist.add(newRecord2);
            
        West_Case_Names__c newRecord3 = new West_Case_Names__c(name='Miscellaneous', West_Case_Name_Category__c='General', West_Case_Name_Activity__c='Miscellaneous', 
        West_Case_Group__c='Student', West_Queue_Name__c='CM - Queue 1', West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
        
        testCasenameslist.add(newRecord3);
            
            
        insert testCasenameslist;
        
        West_Webform_Picklist__c testPicklist = TestDatabaseCMS.createWestWebformPicklist();
        return testCasenameslist;
    }
    
      //added  by suneetha
    public static  List<Blob> GetFileConent()
    {
        
        List<Blob>   attFileContent=new list<Blob>();
         attFileContent.add(Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'));
       attFileContent.add(Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'));
       attFileContent.add(Blob.valueof('SFDCID,CaseName,Subject,Description,Priority\n'));
        return  attFileContent;
    }
      //added  by suneetha
    public static  string Getlargefile()
    {
        
     
          string  samplestr='SFDCID,CaseName,Subject,Description,Priority\n';
           for (Integer i = 0; i < 15;i++){
             samplestr= samplestr+ samplestr;
           }
   
      return samplestr;
        
                // return   largeBlob;
    }
       
    
      //added  by suneetha
    public static NewCaseWebFormController SetData(NewCaseWebFormController testController)
    {
        List<Blob>   attFileContent =GetFileConent();
        testController.attFileContent1 =  attFileContent[0];
        testController.attFileName1 ='CSVUpload1.csv';
        testController.attFileContent2 = attFileContent[1];
        testController.attFileName2 = 'CSVUpload2.csv';
        testController.attFileContent3 =attFileContent[2];
        testController.attFileName3 = 'CSVUpload3.csv';
        testController.secureWebFlag =true;
        testController.boolCaseSubmitted =true;
        testController.contactPhoneFlag =true;
        testController.newattachflg=true;
        testController.source = 'MyWest Test';
        testController.xml_Content = '';  
        testController.attach1=true;
        //Added by Kalyani
        testController.checkbox01 =true;
        testController.modeOfContact = 'Email';
        testController.reasonForContact = 'Application Information';
        testController.state = 'Arizona';
        testController.country = 'USA';
        testController.messageBody = 'Test Message Body';
        testController.phone='8765433456';
        
        return  testController;
    }
      //added  by suneetha
    public  static  NewCaseWebFormController EmptyData(String FirstName,String LastName,String Emailpc)
    {
        Pagereference testPage = Page.NewCaseWebForm;
       
         NewCaseWebFormController testController=new  NewCaseWebFormController();
        /*Setting url parameters*/
       //  ApexPages.currentPage().getParameters().keySet.Add('key','NAME');
       testPage.getParameters().put('fname', FirstName);
       testPage.getParameters().put('lname', LastName);
       testPage.getParameters().put('email',  Emailpc);
        testPage.getParameters().put('NAME', 'MyWest Test');
        //ApexPages.currentPage().getParameters().put('phone', testAccount.PersonHomePhone);
        
         test.setCurrentPage(testPage);
        /*Testing*/
         testController.firstName = FirstName;
        testController.lastName= LastName;
        testController.email = Emailpc;
       testController.source = 'MyWest Test';
        testController.getModeOfContactOptions();
        testController.getReasonForContactOptions();
        testController.getstates();
        testController.secureWebFlag =true;
        testController.boolCaseSubmitted =true;
        testController.contactPhoneFlag =true;
        testController.newattachflg=true;
        testController.xml_Content = '';  
        testController.attach1=true;
        testController.checkbox01 =true;
   
      
      
    return  testController;
    
    }
    
    
    
    //================================================= Test methods=====================================//
      /****Condition where match is found in Account ****/
    static testMethod void foundInAccount(){
        
        
      test.startTest();
      
                /*Creating test Data*/
                 Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
                list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
                 
                NewCaseWebFormController  testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);//added by  suneetha
                testController=SetData(testController);//added by  suneetha
                  
                  
                testController.accountId =testAccount.Account_id__c;
              
              //deleting Attachments
                testController.DeleteAttach1();
                testController.DeleteAttach2();
                testController.DeleteAttach3();
                testController.Save();
        
         
        test.stopTest();    
    }
       /****Condition where match is found in Account ****/
    static testMethod void errofoundInAccount(){
      test.startTest();
            
          /*Creating test Data*/
                 Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
                //list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
         
           //Testing  when empty Data
           NewCaseWebFormController  testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
            testController.accountId =testAccount.Account_id__c;
            
            testController.Save();
        
         
        test.stopTest();    
    }
    
        /****Condition where match is found in Account ****/
    static testMethod void SearchAccount(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
            string LargeBlob= Getlargefile();
             testController.attFileContent1 = Blob.valueof(LargeBlob);
 
               testController.attFileContent2 =Blob.valueof(LargeBlob);
                 testController.attFileContent3 = Blob.valueof(LargeBlob);
          //  testController.accountId =testAccount.Account_id__c;
        
           
            testController.Save();
        
         
        test.stopTest();    
    }
    
    
     /****Condition where match is found in Account ****/
    static testMethod void  phonevaildation(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
       
              testController.modeOfContact = 'Phone';
               testController.Save();
              testController.phone='';
        
        
           
            testController.Save();
            
               testController.phone = '123456789123456723343535354546';
              testController.Save();
        
         
        test.stopTest();    
    }
    
      static testMethod void  emaildation(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
         testController.source = 'MyWest Test';
            testController.Save();
             testController.source = '';
          
               testController.email = '';
            testController.Save();
        
          testController.email = 'test123';
            testController.Save();
            
              testController.email = 'test123456789123456723@test.com';
              testController.Save();
          NewCaseWebFormController.ErrorMessage('invalid email');
        test.stopTest();    
    }
    /****Condition where match is found in Account ****/
    static testMethod void  largefilevalidation1(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
            string LargeBlob= Getlargefile();
             testController.attFileContent1 = Blob.valueof(LargeBlob);
 
             //  testController.attFileContent2 =Blob.valueof(LargeBlob);
                // testController.attFileContent3 = Blob.valueof(LargeBlob);
          //  testController.accountId =testAccount.Account_id__c;
        
           
            testController.Save();
        
         
        test.stopTest();    
    }
    
    /****Condition where match is found in Account ****/
    static testMethod void  largefilevalidation2(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
            string LargeBlob= Getlargefile();
           
 
               testController.attFileContent2 =Blob.valueof(LargeBlob);
                
          //  testController.accountId =testAccount.Account_id__c;
        
           
            testController.Save();
        
         
        test.stopTest();    
    }
    /****Condition where match is found in Account ****/
    static testMethod void  largefilevalidation3(){
      test.startTest();
            /*Creating test Data*/
              Account testAccount = TestDatabaseCMS.createAccountForTesting();  //Sample test Account
              list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
          
           //Testing  when empty Data
         NewCaseWebFormController    testController=EmptyData(testAccount.FirstName,testAccount.LastName,testAccount.Personal_Email__pc);
            testController=SetData(testController);
            string LargeBlob= Getlargefile();
            
                 testController.attFileContent3 = Blob.valueof(LargeBlob);
          //  testController.accountId =testAccount.Account_id__c;
        
           
            testController.Save();
        
         testController.goToWest();
        test.stopTest();    
    }
     static testMethod void    EmptyValues(){
        
      
       test.startTest();
            /*Creating test Data*/
            
         
           //Testing  when empty Data
          NewCaseWebFormController   testController=EmptyData('','','');
            testController.Save();
        
         
        test.stopTest();    
    }
 
   
      /****Condition where match is found in Lead****/
    static testMethod void foundInLead(){
         test.startTest();
        /*Creating test Data*/
        //lead
        Lead testLead = TestDatabaseCMS.createLeadForTesting();
        list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
            NewCaseWebFormController   testController=EmptyData(testLead.FirstName, testLead.LastName,testLead.Personal_Email__c);
            testController=SetData(testController);
            
           testController.Save();
        
        test.stopTest();    
    }
   
    
    /****Condition where match is not found in salesforce ****/
    static testMethod void notfound(){
         test.startTest();
         list<West_Case_Names__c> testcases=   createWestCaseNames_webform();//Sample test CaseNames
     NewCaseWebFormController  testController=EmptyData('TestName1','TestLast2','Test.te@te.com');
            testController=SetData(testController);
            
        
        testController.Save();
        
        test.stopTest();    
    }
    
}